Loading estimates for major pollutants and hydrologic inputs to Tampa Bay. Estimates are tons per year and are unique to each major bay segment. All estimates from Janicki Environmental. Source content here.
p <- ggplot(tndat, aes(x = YEAR, y = TN_tons, fill = SOURCE)) +
geom_area(alpha = 0.6) +
theme_minimal() +
theme(
axis.title.x = element_blank(),
axis.text.x = element_text(angle = 45, size = 7, hjust = 1),
axis.ticks.x = element_line(),
legend.title = element_blank()
) +
scale_y_continuous(expand = c(0, 0)) +
scale_x_continuous(expand = c(0, 0), breaks = seq(1985, 2019)) +
scale_fill_discrete_qualitative(palette = 'Dynamic') +
facet_wrap(~ bay_segment, ncol = 1, scales = 'free_y') +
labs(
y = 'Total Nitrogen (tons/yr)'
)
p
cols <- qualitative_hcl(length(levs), palette = "Dynamic")
for(lev in seq_along(levs)){
toplo <- tndat %>%
filter(bay_segment %in% !!levs[lev]) %>%
spread(SOURCE, TN_tons)
showleg <- F
if(lev == 1)
showleg <- T
p <- plot_ly(toplo) %>%
add_markers(x = ~YEAR, y = ~NPS, color = I(cols[5]), stackgroup = 'one', mode = 'none', marker = list(opacity = 0, size = 0),
showlegend = showleg, legendgroup = 'grp5', name = 'NPS') %>%
add_markers(x = ~YEAR, y = ~IPS, color = I(cols[4]), stackgroup = 'one', mode = 'none', marker = list(opacity = 0, size = 0),
showlegend = showleg, legendgroup = 'grp4', name = 'IPS') %>%
add_markers(x = ~YEAR, y = ~GWS, color = I(cols[3]), stackgroup = 'one', mode = 'none', marker = list(opacity = 0, size = 0),
showlegend = showleg, legendgroup = 'grp3', name = 'GWS') %>%
add_markers(x = ~YEAR, y = ~DPS, color = I(cols[2]), stackgroup = 'one', mode = 'none', marker = list(opacity = 0, size = 0),
showlegend = showleg, legendgroup = 'grp2', name = 'DPS') %>%
add_markers(x = ~YEAR, y = ~AD, color = I(cols[1]), stackgroup = 'one', mode = 'none', marker = list(opacity = 0, size = 0),
showlegend = showleg, legendgroup = 'grp1', name = 'AD') %>%
add_annotations(
text = ~unique(bay_segment),
x = 0.5,
y = 1.2,
yref = "paper",
xref = "paper",
xanchor = "middle",
yanchor = "top",
showarrow = FALSE,
font = list(size = 15)
)
if(lev == 3)
p <- p %>%
layout(
yaxis = list(title = 'Total Nitrogen (tons/yr)')
)
if(lev != 3)
p <- p %>%
layout(
yaxis = list(title = NA)
)
nm <- paste0('p', lev)
assign(nm, p)
}
subplot(p1, p2, p3, p4, p5, shareX = T, nrows = length(levs), shareY = F, titleY = T) %>%
layout(
xaxis = list(title = NA, gridcolor = '#FFFFFF'),
barmode = 'stack',
legend = list(title = list(text = 'Source'))
)